/**
 * Created by Administrator on 2017/9/19.
 */
var resetItemClickListener  = function () {

    $('.item-detail').click(function(e) {
        var orderId  = $(this).parents(".menu-item").attr("Order-id");
        var tableNum = $(this).next(".tableNum").attr("value");
        var name     = $(this).children(".name").attr("item-name");
        var count    = $(this).nextAll(".count").attr("value");
        var price    = $(this).children(".price").attr("item-price");
        var dish     = $(this).nextAll(".dish").attr("value");

        //弹出框设置
        $('.revealTableNum').html("第 "+tableNum+" 桌");

        var jsonStr = $('#inputData').val();
        var jsonObj = JSON.parse(jsonStr);
        var dishsHtml = "";
        for (var i = 0; i < jsonObj.length; i ++) {
            if (jsonObj[i].orderId == orderId) {
                var dishs = jsonObj[i].dish;
                for (var j = 0; j < dishs.length; j ++) {
                    dishsHtml +=
                        "<li class='checkout-tablerow'>"+
                            "<div class='cell itemname  text_align_left' >"+dishs[j].name+"</div>"+
                            "<div class='cell itemquantity  text_align_left'  style='text-align: center'>"+dishs[j].count+"</div>"+
                            "<div class='cell itemtotal  text_align_left'  style='text-align: center;'>"+dishs[j].price+"</div> " +
                        "</li>";
                }
            }//if
        }//for

        $('#checkout-body').html(dishsHtml);
        //弹出
        $('#header-login').trigger('click');

        //console.log(dish);
    });
};

(function($){
    //关闭按钮
    $('#closeReveal').click(function(){
        //alert("无法关闭？？");
        //$('#header-login').trigger('reveal:close');
        //弹出层关闭
        $('.close-reveal-modal').trigger('click');

    });

    resetItemClickListener();
})(jQuery);